package com.cpe.web.intercepter.base;

import java.util.List;
import java.util.Map;

import org.springframework.web.servlet.HandlerInterceptor;

import com.google.common.collect.Lists;
import com.sql.data.request.RequestSource;

public abstract class InterceptorConfigurer {
	/**
	 * 加载分流拦截器
	 */
	public void load(Map<String, List<HandlerInterceptor>> interceptorMappings) {
		interceptorMappings.put(RequestSource.CMS.getSource(), Lists.newArrayList(getCMSInterceptors()));
		interceptorMappings.put(RequestSource.PC.getSource(), Lists.newArrayList(getPCInterceptors()));
		interceptorMappings.put(RequestSource.MOBILE.getSource(), Lists.newArrayList(getMobileInterceptors()));
		interceptorMappings.put(RequestSource.WECHAT.getSource(), Lists.newArrayList(getMobileInterceptors()));
		interceptorMappings.putAll(getCustomInterceptors());
	}

	/**
	 * 加载全局拦截器
	 */
	public void load(List<HandlerInterceptor> preInterceptors, List<HandlerInterceptor> postInterceptors) {
		preInterceptors.addAll(Lists.newArrayList(getPreInterceptors()));
		postInterceptors.addAll(Lists.newArrayList(getPostInterceptors()));
	}

	/**
	 * 全局拦截器
	 */
	protected abstract HandlerInterceptor[] getPreInterceptors();

	protected abstract HandlerInterceptor[] getPostInterceptors();

	/**
	 * 分流拦截器
	 */
	protected abstract HandlerInterceptor[] getCMSInterceptors();

	protected abstract HandlerInterceptor[] getMobileInterceptors();

	protected abstract HandlerInterceptor[] getWechatInterceptors();

	protected abstract HandlerInterceptor[] getPCInterceptors();

	protected abstract Map<String, List<HandlerInterceptor>> getCustomInterceptors();
}
